package com.ruoyi.project.dict.cizunew.service.impl;

import com.ruoyi.common.constant.RedisKey;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.dict.cizunew.domain.Cizu;
import com.ruoyi.project.dict.cizunew.mapper.CizuMapper;
import com.ruoyi.project.dict.cizunew.service.ICizuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * cizunewService业务层处理
 *
 * @author shixiangwen
 * @date 2020-06-16
 */
@Service
@DataSource(DataSourceType.DICT)
public class CizuServiceImpl implements ICizuService {


    public static final Logger log = LoggerFactory.getLogger(CizuServiceImpl.class);

    @Autowired
    private CizuMapper cizuMapper;

    @Autowired
    @Qualifier("commonRedisTemplate")
    RedisTemplate<String, String> redisTemplate;

    /**
     * 查询cizunew
     *
     * @param id cizunewID
     * @return cizunew
     */
    @Override
    public Cizu selectCizuById(Long id) {
        return cizuMapper.selectCizuById(id);
    }

    /**
     * 查询cizunew列表
     *
     * @param cizu cizunew
     * @return cizunew
     */
    @Override
    public List<Cizu> selectCizuList(Cizu cizu) {
        return cizuMapper.selectCizuList(cizu);
    }

    /**
     * 新增cizunew
     *
     * @param cizu cizunew
     * @return 结果
     */
    @Override
    public int insertCizu(Cizu cizu) {
        return cizuMapper.insertCizu(cizu);
    }

    /**
     * 修改cizunew
     *
     * @param cizu cizunew
     * @return 结果
     */
    @Override
    public int updateCizu(Cizu cizu) {
        int effect = cizuMapper.updateCizu(cizu);
        if (effect > 0) {
            Cizu old = cizuMapper.selectCizuById(cizu.getId());
            String key = RedisKey.Dict.CizuKey(old.getCi());
            log.info("start to delete:" + key);
            redisTemplate.delete(key);
        }
        return effect;
    }

    /**
     * 删除cizunew对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteCizuByIds(String ids) {
        return cizuMapper.deleteCizuByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除cizunew信息
     *
     * @param id cizunewID
     * @return 结果
     */
    @Override
    public int deleteCizuById(Long id) {
        return cizuMapper.deleteCizuById(id);
    }
}
